package com.zrrd.gmall.payment.controller;

import com.alipay.api.AlipayApiException;
import com.zrrd.gmall.payment.service.AlipayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/api/payment/alipay")
public class AliPayController {

    @Autowired
    private AlipayService alipayService;

    //提交支付
    @RequestMapping("/submit/{orderId}")
    public String submit(@PathVariable("orderId") Long orderId, HttpServletResponse response){
        String aliPay = "";
        try {
            aliPay = alipayService.createAlipay(orderId);
        } catch (AlipayApiException e) {
            System.err.println("支付异常===>" + e.getMessage());
        }
        return aliPay;
    }
}
